/*
 * @Author: your name
 * @Date: 2021-12-21 10:37:11
 * @LastEditTime: 2021-12-21 19:42:35
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \day10 react\my-app\src\store\action.js
 */
import axios from "axios"

export const getHome = async (dispatch) => {
    let res = await axios.get("/home");
    dispatch({
        type: "HOME",
        home: res.data
    })
}

export const getclassify=(type)=>{
    return async dispatch=>{
        let res=await axios.get("/classify?type="+type)
        dispatch({
            type:"CLASSIFY",
            classify:res.data
        })
    }
}

// export const change_Check=(id)=>{
//     return {
//         type:"CHANGECHECK",
//         payload:id
//     }
// }

export const changeStart=(obj)=>{
    return async dispatch=>{
        let res=await axios.put("/classify/"+obj.id,{...obj,check:!obj.check})
        dispatch({
            type:"CHANGESTART",
            payload:res.data
        })
    }
}

export const change_Coll=(index)=>{
    return async dispatch=>{
        let res=await axios.get("/classify?flag="+(index+1))
        console.log(res);
        dispatch({
            type:"CHANGECOLL",
            payload:res.data
        })
    }
}